<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.bootcss.com/socket.io/2.3.0/socket.io.js"></script>
    <script>
        window.onload = function () {
            const socket = io.connect('/');
            //监听与服务器端的连接成功事件
            socket.on('connect', function () {
                console.log('连接成功');
                setInterval(function() {
                    socket.send('welcome client');
                }, 3000)
            });
            //监听与服务器端断开连接事件
            socket.on('disconnect', function () {
                console.log('断开连接');
            });
        };
    </script>
</body>

</html>